import jdk.internal.dynalink.beans.StaticClass;
import sun.misc.InvalidJarIndexException;

/**
 * Created by loso on 2017/3/15.
 */
public class _345_ReverseVowelsofaString {

    static char[] c = new char[]{'a','e','i','o','u','A','E','I','O','U'};

    public static void main(String[] args) {
        System.out.println(reverseVowels("hello"));
    }

    public static String reverseVowels(String s) {
        if (s.isEmpty()){
            return "";
        }
        StringBuilder sb = new StringBuilder(s);
        int indexstart = 0;
        int indexend = s.length()-1;
        while (true){
            while(!isVowels(sb.charAt(indexstart))){
                indexstart++;
                if(indexstart == sb.length()){
                    return sb.toString();
                }
            }
            while(!isVowels(sb.charAt(indexend))){
                indexend--;
                if(indexend == 0){
                    return sb.toString();
                }
            }
            if (indexstart>=indexend) {
                return sb.toString();
            }
                char temp = sb.charAt(indexend);
                sb.setCharAt(indexend,sb.charAt(indexstart));
                sb.setCharAt(indexstart,temp);
                indexstart++;
                indexend--;
        }
    }

    public static boolean isVowels(char i){
        for (char ch :
                c) {
            if(ch == i){
                return true;
            }
        }
        return false;
    }
}
